package com.example.pcl.controller.counselor;


import com.example.pcl.pojo.dto.AppointmentQueryDto;
import com.example.pcl.pojo.dto.AppointmentStatusDTO;
import com.example.pcl.pojo.dto.BatchCancelDto;
import com.example.pcl.pojo.vo.AppointmentVo;
import com.example.pcl.result.PageResult;
import com.example.pcl.result.Result;
import com.example.pcl.service.IAppointmentsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 预约表，记录学生与心理咨询师的预约信息 前端控制器
 * </p>
 *
 * @author xx
 * @since 2024-12-17
 */
@RestController("counselorAppointmentsController")
@RequestMapping("/user/counselor/appointments")
@Slf4j
@Tag(name = "管理端心理咨询师预约记录相关接口")
@RequiredArgsConstructor
public class AppointmentsController {


    private final IAppointmentsService appointmentService;



    /**
     * 更新预约状态
     * a
     * appointmentStatusDTO dto
     *
     * @return 操作结果
     */
    @PutMapping("/update-status")
    @Operation(summary = "更新预约状态")
    public Result<?> updateAppointmentStatus(@RequestBody AppointmentStatusDTO appointmentStatusDTO) {
        log.info("心理咨询师更新预约状态: {}", appointmentStatusDTO);
        appointmentService.updateAppointmentStatus(appointmentStatusDTO);
        return Result.success("预约状态更新成功");
    }

    /**
     * 查询预约详情
     *
     * @param appointmentId 预约ID
     * @return 预约详情
     */
    @GetMapping("/detail/{appointmentId}")
    @Operation(summary = "查询预约详情")
    public Result<?> getAppointmentDetail(@PathVariable Integer appointmentId) {
        log.info("心理咨询师查询预约详情: appointmentId={}", appointmentId);
        AppointmentVo appointment = appointmentService.getAppointmentDetail(appointmentId);
        return Result.success(appointment, "预约详情查询成功");
    }

    /**
     * 分页查询预约列表
     *
     * @param queryDto 查询条件
     * @return 分页数据
     */
    @GetMapping("/list")
    @Operation(summary = "分页查询预约列表")
    public Result<?> getAppointmentList(AppointmentQueryDto queryDto) {
        log.info("心理咨询师分页查询预约列表: {}", queryDto);
        PageResult<AppointmentVo> pageResult = appointmentService.getAppointmentList(queryDto);
        return Result.success(pageResult, "预约列表查询成功");
    }


    /**
     * 批量取消预约
     *
     * @param cancelDto 批量取消参数
     * @return 操作结果
     */
    @PutMapping("/batch-cancel")
    @Operation(summary = "批量取消预约")
    public Result<?> batchCancelAppointments(@RequestBody @Validated BatchCancelDto cancelDto) {
        log.info("批量取消预约: {}", cancelDto);
        appointmentService.batchCancelAppointments(cancelDto);
        return Result.success("批量取消成功");
    }
}
